/**
 * 模拟
 */
public class Leetcode1614 {
    public static void main(String[] args) {
        System.out.println(maxDepth("(1+(2*3)+((8)/4))+1"));
        System.out.println(maxDepth("(1)+((2))+(((3)))"));
        System.out.println(maxDepth("1+(2*3)/(2-1)"));
        System.out.println(maxDepth("1"));
    }
    public static int maxDepth(String s) {
        char[] chars = s.toCharArray();
        int n = chars.length;

        int maxDepth = 0;

        int leftNumber = 0;
        for (int i = 0; i < n; i++) {
            if (chars[i] == '(') {
                leftNumber++;
                maxDepth = Math.max(leftNumber, maxDepth);
            } else if (chars[i] == ')') {
                leftNumber --;
            }
        }

        return maxDepth;
    }
}
